<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of WriteOff
 *
 * @author Administrator
 */
class PurchaseList extends WMS_Controller
{

    var $whsCode;

    function __construct()
    {
        parent::__construct();
        $gp = gp();
        $userData = $this->session->userdata('users');
        $this->whsCode = $userData['user_main_whs_code'];
        //加载模型
        $this->load->service('wms/accessory_purchase_service');
        $this->load->service('wms/api_service');
        $this->load->service('wms/sap_service');
        $this->load->service('wms/warehouse_list_service');
        $this->load->service('wms/time_service');
    }

    public function show($status=1)
    {
        //锁死仓库
        $whs = $this->whsCode;
        $wherein = array('whs_code' => $whs);
        $where = array();
        if ('ALL' != $status)
        {
            $where['status'] = $status;
        }

        $gp = gp();
        $sku = $gp['sku'] ? trim($gp['sku']) : '';
        $whs = $gp['whs'] ? $gp['whs'] : '';
        $startTime = $gp['startTime'] ? $gp['startTime'] : '';
        $endTime = $gp['endTime'] ? $gp['endTime'] : '';
        $page = $gp['page'] ? intval($gp['page']) : 1;
        //
        $str = '?';
        $page_size = 15;
        if ('' != $sku)
        {
            if (stristr($sku, "wx"))
            {
                $where['order_id'] = $sku;
            }
            else
            {
                $where['sku'] = $sku;
            }
            $str.=$str;
        }
        if ('' != $whs)
        {
            $where['whs_code'] = $whs;
            $str.='&' . $whs;
        }
        if ('' != $startTime)
        {
            $where['add_date>'] = strtotime($startTime);
            $str.='&' . $startTime;
        }
        if ('' != $endTime)
        {
            $where['add_date<'] = strtotime($endTime);
            $str.='&' . $endTime;
        }

        //分页查询
        $this->load->library('pagination');
        $config['page_query_string'] = TRUE;
        $config['base_url'] = blang_url('wms/PurchaseList/show' . '/' . $status . $str);
        $data['status_url'] = blang_url('wms/PurchaseList/show' . '/' . $status . $str);
        $config['total_rows'] = $this->accessory_purchase_service->get_count_group($where);
        $config['uri_segment'] = config_item('enable_lang') ? 5 : 4;
        $config['per_page'] = $page_size;
        $this->pagination->initialize($config);
        $data['pageShow'] = $this->pagination->create_links();
        //分页结束
        //获取产品库存列表
        $accessory_purchase_list = $this->accessory_purchase_service->get_list_group(($page - 1) * $page_size, $page_size, $where);
        $status_list = $this->accessory_purchase_service->get_status();
        foreach ($accessory_purchase_list as $key => $value)
        {
            $value['child'] = $this->time_service->show_time($value['child'], 'add_date');
            $accessory_purchase_list[$key] = $this->api_service->fields_erp_product_info($value);
        }
        $data['accessory_purchase_list'] = $accessory_purchase_list;
        $data['status'] = $status_list;
        $data['list_status'] = $status;
        $data['whs'] = $this->warehouse_list_service->fields_whs_array($this->whsCode);
        $this->load->view('defaults/wms/accessory_purchase_list', $data);
        $this->load->view('defaults/common/footer', $data);
    }

    public function need_batch($status)
    {
        $gp = gp();
        $ids = explode(",", $gp['ids']);
        $success = $this->accessory_purchase_service->chuange_status_by_ids($ids, $status);

        $urlParamList = $this->input->get();
        unset($urlParamList['ids']);
        $urlParam = @http_build_query($urlParamList);
        redirect(blang_url('wms/PurchaseList/show/' . $status . '?' . $urlParam));
    }

}

?>
